﻿using Jint;
using System;
using System.Collections.Generic;
using System.Text;

namespace RAP.Framework.Libary.JScriptEngine
{
	public class JSEngine
	{

		private Engine _engine;

		public JSEngine( )
		{
			_engine = new Engine();
		}

		/// <summary>
		/// 添加参数
		/// </summary>
		/// <param name="name"></param>
		/// <param name="obj"></param>
		public void SetParameter( string name, object obj )
		{
			_engine.SetValue( name, obj );
		}

		/// <summary>
		/// 执行脚本
		/// </summary>
		/// <param name="script"></param>
		/// <returns></returns>
		public object Run( string script )
		{
			return _engine.Execute( script ).GetCompletionValue().ToObject();
		}
	}
}
